<template>
  <div class="closing">
    <div>
      <el-button size="mini" @click="handleGetUntreated">{{ $t('btn.reload') }}</el-button>
      <el-button type="primary" size="mini" @click="isClosingDialog=true">{{ $t('market.filter') }}</el-button>
    </div>
    <div class="header">
      <div class="header-name">
        <span>{{ $t('market.period') }}</span>
        <el-input v-model="period" size="mini" disabled />
      </div>
      <!--      当前关账期间-->
      <dataRow />
    </div>
    <div class="table-content">
      <el-tabs v-model="activeName" @tab-click="tabClick">
        <el-tab-pane :label="$t('menu.collect')" name="first">
          <jc-table
            v-loading="loading"
            :table-data="tableData"
            :table-header="tableHeader"
            :table-height="tableHeight"
            serial
            sortable
            :get-summaries="getSummaries"
            show-summary
            @rowClick="rowClick"
          >
            <template v-slot:btnState="col">
              <el-link type="primary" @click="pushmob(col.scope.row)">{{ col.scope.row.fbillNo }}</el-link>
            </template>
            <!--    物料编码    -->
            <template v-slot:orderSlot="col">
              <el-link type="primary" @click="jumpMateriel(col.scope.row)">
                {{ col.scope.row.fnumber }}
              </el-link>
            </template>
            <!--领料状态-->
            <template v-slot:text3Slot="col">
              <el-tag :type="col.scope.row.pickColor">{{ col.scope.row.fpickstatus }}</el-tag>
            </template>
          </jc-table>
          <jc-pagination
            :total="subDetails.total"
            :page.sync="subDetails.pageNum"
            :limit.sync="subDetails.pageSize"
            @pagination="handleGetUntreated"
          />
        </el-tab-pane>
        <el-tab-pane :label="$t('market.childDetail')" name="two">
          <jc-table
            v-loading="loading"
            :table-data="tableData1"
            :table-header="tableHeader1"
            :table-height="tableHeight"
            serial
            sortable
          >
            <!--    物料编码    -->
            <template v-slot:orderSlot="col">
              <el-link type="primary" @click="jumpMateriel(col.scope.row)">
                {{ col.scope.row.fnumber }}
              </el-link>
            </template>
          </jc-table>
          <!--          <jc-pagination-->
          <!--            :total="subDetails.total"-->
          <!--            :page.sync="subDetails.pageNum"-->
          <!--            :limit.sync="subDetails.pageSize"-->
          <!--            @pagination="handleGetUntreated"-->
          <!--          />-->
        </el-tab-pane>
      </el-tabs>

    </div>
    <!-- 选择时间 -->
    <el-dialog
      v-dialogDrag
      :title="$t('market.checkPeriod')"
      model
      :visible.sync="isClosingDialog"
      :close-on-click-modal="false"
      width="600px"
      center
    >
      <div>
        <el-form :model="subDetails" size="mini" label-width="100px">
          <el-form-item :label="$t('market.startPeriod')">
            <el-date-picker
              v-model="subDetails.start"
              type="month"
              value-format="yyyy-MM"
              placeholder="选择期间"
            />
          </el-form-item>
          <el-form-item :label="$t('market.endPeriod')">
            <el-date-picker
              v-model="subDetails.end"
              type="month"
              value-format="yyyy-MM"
              placeholder="选择期间"
            />
          </el-form-item>
          <el-form-item :label="$t('market.srcbillno')">
            <el-input v-model.trim="subDetails.fbillNo" />
          </el-form-item>
          <el-form-item :label="$t('market.fmaterial')">
            <el-input v-model.trim="subDetails.fnumber" />
          </el-form-item>
          <!--          <el-form-item :label="$t('market.stockname')">-->
          <!--            <el-input v-model.trim="subDetails.stockName" />-->
          <!--          </el-form-item>-->
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isClosingDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button type="primary" @click="initialCon">{{ $t('btn.confirm') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryMoInstockAndPickDetailList, queryMoInstockAndPickList
} from '@/api/financial/warehousing'
import dataRow from '@/views/financial/company/components/dataRow'
import searData from '@/components/Search/mixin'
import { toPickStues } from '@/components/ToMxamineState'

export default {
  name: 'InventoryDetail',
  components: {
    dataRow
  },
  mixins: [searData],
  data() {
    return {
      activeName: 'first',
      subDetails: {
        start: '',
        end: '',
        stockName: '',
        materialNumber: '',
        frombillNo: '',
        pageSize: 200,
        pageNum: 1,
        total: 0
      },
      openDelay: 1000,
      period: '',
      loading: false,
      isClosingDialog: false,
      // 表头
      tableData: [], // 存货收发存明细表
      tableHeight: '70vh',
      tableHeader: [
        { label: this.$t('menu.collect'), type: 'state', prop: 'fbillNo', minWidth: '120' },
        { label: this.$t('market.fseq'), prop: 'fseq', minWidth: '80' },
        { label: this.$t('market.moDate'), prop: 'fdate', minWidth: '150' },
        { label: this.$t('market.putStoageDate'), prop: 'instockfdate', minWidth: '150' },
        { label: this.$t('market.productNo'), type: 'order', prop: 'fnumber', minWidth: '150' },
        { label: this.$t('market.productmolde'), prop: 'fmodel', minWidth: '150' },
        { label: this.$t('market.productName'), prop: 'fname', minWidth: '150' },
        { label: this.$t('market.productNum'), prop: 'fqty', width: '80', align: 'right' },
        { label: this.$t('market.beginNum'), prop: 'beginNum', width: '80', align: 'right' },
        { label: this.$t('market.periodNum'), prop: 'periodNum', width: '80', align: 'right' },
        { label: this.$t('market.instockNum'), prop: 'ableInstockNum', width: '80', align: 'right' },
        { label: this.$t('market.pickstatus'), type: 'text3', prop: 'fpickstatus', minWidth: '80' }
      ],
      tableData1: [],
      tableHeader1: [
        { label: this.$t('menu.collect'), prop: 'fmoBillNo' },
        { label: this.$t('market.proOrderSeq'), prop: 'fmoentrySeq' },
        { label: this.$t('market.subitemNum'), type: 'order', prop: 'fnumber' },
        { label: this.$t('market.childModel'), prop: 'fmodel' },
        { label: this.$t('market.subitemName'), prop: 'fname' },
        { label: this.$t('market.shouldNum'), prop: 'fstdQty', align: 'right' },
        { label: this.$t('market.beginNum'), prop: 'periodNum', align: 'right' },
        { label: this.$t('market.periodNum'), prop: 'nowNum', align: 'right' }
      ]
    }
  },
  created() {
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 260px)' : '73vh'
  },
  methods: {
    // 过滤确认
    initialCon() {
      this.isClosingDialog = false
      const { start, end } = this.subDetails
      this.period = start + ' -- ' + end
      this.handleGetUntreated()
    },
    // 获取生产入库领料查询
    async handleGetUntreated() {
      this.loading = true
      const DATA = { ...this.subDetails }
      await queryMoInstockAndPickList(DATA).then(RES => {
        if (RES.code === 0) {
          this.loading = false
          this.tableData = RES.data.list.map(item => {
            return toPickStues(item)
          })
          this.subDetails.total = RES.data.total
        } else {
          this.loading = false
          this.$confirm(RES.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 跳转生产委外订单
    pushmob(ev) {
      const { prdOrSub, fbillNo } = ev
      if (prdOrSub === 1) { // 生产
        this.$router.push({ path: `/proOrderDetails/${fbillNo}` })
      } else if (prdOrSub === 2) { // fbilltypeId === 20 委外
        this.$router.push({ path: `/outOrderDetails/${fbillNo}` })
      }
    },
    // 搜索
    handleQuerySonClass() {
      this.currentPage = 1
      this.handleGetUntreated()
    },
    rowClick(row) {
      this.moEntryId = row.moEntryId
      this.prdOrSub = row.prdOrSub
    },
    tabClick(tab) {
      if (tab.name === 'two') {
        this.costShareList()
      }
    },
    // 分摊明细
    costShareList() {
      const { start, end } = this.subDetails
      const DATA = {
        start: start,
        end: end,
        moEntryId: this.moEntryId,
        prdOrSub: this.prdOrSub
      }
      queryMoInstockAndPickDetailList(DATA).then(res => {
        if (res.code === 0) {
          this.tableData1 = res.data.list
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.closing {
  @include listBom;
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .header{
    margin-top: 10px;
    .header-name{
      span {
        width: 100px;
        margin-right: 10px;
        text-align: right;
      }
    }
  }
}
</style>
